<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?>
    	<?php if(isset($breadcrumb['href']) && $breadcrumb['href'] != '' && $breadcrumb['href'] != '#') {?>
	    	<a href="<?php echo $breadcrumb['href']; ?>">
	    		<?php echo $breadcrumb['text']; ?>
	    	</a>
    	<?php }else{?>
    		<?php echo $breadcrumb['text']; ?>
    	<?php }?>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/news.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a onclick="location = '<?php echo $cancel; ?>';" class="button"><?php echo $button_cancel; ?></a></div>
    </div>
    <div class="content">
      <div id="tabs" class="htabs">
      	<a href="#tab-general"><?php echo $tab_general; ?></a>
      	<a href="#tab-data"><?php echo $tab_data; ?></a>
      </div>
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
        <div id="tab-general">
          <div id="languages" class="htabs">
            <?php foreach ($languages as $language) { ?>
            <a href="#language<?php echo $language['language_id']; ?>"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /> <?php echo $language['name']; ?></a>
            <?php } ?>
          </div>
          <?php foreach ($languages as $language) { ?>
          <div id="language<?php echo $language['language_id']; ?>">
            <table class="form">
              <tr>
                <td>
	                <span class="required">*</span>
	                <?php echo $common_news_title; ?>
	            </td>
                <td>
                	<input type="text" name="news_article_description[<?php echo $language['language_id']; ?>][title]" size="100" 
                		value="<?php echo isset($news_article_description[$language['language_id']]) ? $news_article_description[$language['language_id']]['title'] : ''; ?>" />
                  	<?php if (isset($error_title[$language['language_id']])) { ?>
                  	<span class="error"><?php echo $error_title[$language['language_id']]; ?></span>
                  	<?php } ?>
                </td>
              </tr>
              <tr>
                <td>
	                <span class="required">*</span>
                  	<?php echo $entry_header; ?>
                </td>
                <td>
                	<textarea name="news_article_description[<?php echo $language['language_id']; ?>][header]" cols="120" rows="5"><?php echo isset($news_article_description[$language['language_id']]) ? $news_article_description[$language['language_id']]['header'] : ''; ?></textarea>
                	<?php if (isset($error_header[$language['language_id']])) { ?>
                  	<span class="error"><?php echo $error_header[$language['language_id']]; ?></span>
                  	<?php } ?>
                </td>
              </tr>
              <tr>
                <td>
	                <span class="required">*</span>
                  	<?php echo $entry_body; ?>
                </td>
                <td>
                	<textarea name="news_article_description[<?php echo $language['language_id']; ?>][body]" id="body<?php echo $language['language_id']; ?>" cols="40" rows="5"><?php echo isset($news_article_description[$language['language_id']]) ? $news_article_description[$language['language_id']]['body'] : ''; ?></textarea>
                	<?php if (isset($error_body[$language['language_id']])) { ?>
                  	<span class="error"><?php echo $error_body[$language['language_id']]; ?></span>
                  	<?php } ?>
                </td>
              </tr>
              <tr>
                <td><?php echo $entry_meta_description; ?></td>
                <td>
                	<textarea name="news_article_description[<?php echo $language['language_id']; ?>][meta_description]" cols="40" rows="5"><?php echo isset($news_article_description[$language['language_id']]) ? $news_article_description[$language['language_id']]['meta_description'] : ''; ?></textarea></td>
              </tr>
              <tr>
                <td><?php echo $entry_meta_keyword; ?></td>
                <td><textarea name="news_article_description[<?php echo $language['language_id']; ?>][meta_keyword]" cols="40" rows="5"><?php echo isset($news_article_description[$language['language_id']]) ? $news_article_description[$language['language_id']]['meta_keyword'] : ''; ?></textarea></td>
              </tr>
            </table>
          </div>
          <?php } ?>
        </div>
        <div id="tab-data">
          <table class="form">
            <tr>
              <td><?php echo $common_news_type; ?></td>
              <td><select name="type_id">
                  <?php foreach ($news_types as $news_type) { ?>
                  <?php if ($news_type['type_id'] == $type_id) { ?>
                  <option value="<?php echo $news_type['type_id']; ?>" selected="selected"><?php echo $news_type['name']; ?></option>
                  <?php } else { ?>
                  <option value="<?php echo $news_type['type_id']; ?>"><?php echo $news_type['name']; ?></option>
                  <?php } ?>
                  <?php } ?>
                </select>
             </td>
            </tr>
            <tr>
              <td><span class="required">*</span> <?php echo $common_category; ?></td>
              <td>
              	<div id="tdCategory">
              	</div>
              	<?php if (isset($error_category)) { ?>
                <span class="error"><?php echo $error_category; ?></span>
                <?php } ?>
              </td>
            </tr>
            <tr>
              <td><?php echo $entry_image; ?></td>
              <td valign="top"><div class="image">
                <img src="<?php echo $thumb; ?>" alt="" id="thumb" />
                <input type="hidden" name="image" value="<?php echo $image; ?>" id="image" />
                <br /><a onclick="javascript:image_upload('image', 'news/' + $('select[name=\'type_id\']').val(), 'thumb');"><?php echo $text_browse; ?></a>
                &nbsp;&nbsp;|&nbsp;&nbsp;<a onclick="$('#thumb').attr('src', '<?php echo $no_image; ?>'); $('#image').attr('value', '');"><?php echo $text_clear; ?></a>
                </div>
              </td>
            </tr>
            <tr>
              <td><?php echo $entry_keyword; ?></td>
              <td><input type="text" name="keyword" value="<?php echo $keyword; ?>" /></td>
            </tr>
            <tr>
              <td><?php echo $entry_sort_order; ?></td>
              <td><input type="text" name="sort_order" value="<?php echo $sort_order; ?>" size="1" /></td>
            </tr>
            <tr>
              <td><?php echo $entry_status; ?></td>
              <td><select name="status">
                  <?php if ($status) { ?>
                  <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                  <option value="0"><?php echo $text_disabled; ?></option>
                  <?php } else { ?>
                  <option value="1"><?php echo $text_enabled; ?></option>
                  <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                  <?php } ?>
                </select></td>
            </tr>
          </table>
        </div>
      </form>
    </div>
  </div>
  <div style="display: none">
  	<table>
		<tr>
			<td>
                <?php foreach ($categories as $id => $categoryList) { ?>
				<div id="categories_<?php echo $id;?>">
					<select name="category_id">
						<option value=""><?php echo $text_select;?></option>
						<?php $class = 'old'; ?>
	                  	<?php foreach ($categoryList as $category) { ?>
		                  	<?php if($category_id == $category['category_id']){?>
								<option selected="selected" value="<?php echo $category['category_id'];?>"><?php echo $category['name'];?></option>
							<?}else{?>
								<option value="<?php echo $category['category_id'];?>"><?php echo $category['name'];?></option>
							<?php }?>
					  	<?php }?>
					</select>
				</div>
				<?php } ?>
			</td>
		</tr>
	</table>    
</div>
</div>
<script type="text/javascript" src="view/javascript/ckeditor/ckeditor.js"></script> 
<script type="text/javascript">
	$('#tabs a').tabs(); 
	$('#languages a').tabs();
	
	<?php foreach ($languages as $language) { ?>
	CKEDITOR.replace('body<?php echo $language['language_id']; ?>', {
		filebrowserBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
		filebrowserImageBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
		filebrowserFlashBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
		filebrowserUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
		filebrowserImageUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
		filebrowserFlashUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>'
	});
	<?php } ?>
	
	$('select[name=\'type_id\']').change(function(){
		$('#tdCategory').html($('#categories_' + $(this).val()).clone());	
	});
	
	$(document).ready( function() {
		$('#tdCategory').html($('#categories_'+ <?php echo $type_id;?>).clone());
	});

	function image_upload(field, folder, thumb) {
		$('#dialog').remove();
		
		$('#content').prepend('<div id="dialog" style="padding: 3px 0px 0px 0px;"><iframe src="index.php?route=common/filemanager&token=<?php echo $token; ?>&restaurant_id=<?php echo isset($this->request->get['restaurant_id'])?$this->request->get['restaurant_id']:$this->restaurant->getRestaurantId();?>&folder=' + encodeURIComponent(folder) + '&field=' + encodeURIComponent(field) + '" style="padding:0; margin: 0; display: block; width: 100%; height: 100%;" frameborder="no" scrolling="auto"></iframe></div>');
		
		$('#dialog').dialog({
			title: '<?php echo $text_image_manager; ?>',
			close: function (event, ui) {
				if ($('#' + field).attr('value')) {
					$.ajax({
						url: 'index.php?route=common/filemanager/image&token=<?php echo $token; ?>&image=' + encodeURIComponent($('#' + field).val()),
						dataType: 'text',
						success: function(data) {
							$('#' + thumb).replaceWith('<img src="' + data + '" alt="" id="' + thumb + '" />');
						}
					});
				}
			},
			bgiframe: false,
			width: 800,
			height: 400,
			resizable: false,
			modal: false
		});
	};
</script> 
<?php echo $footer; ?>